﻿//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//    Crolengi, this program (a part of program) is gameengine based on C++\Directx
//    Copyright (C) 2008 Pashinin Anton Alekseevich (Crol)
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//    (INCLUDING NEGLIGENCE OR OTHERWISE) 
//    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
//    EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//    Contacts: 
//    Mail: crolengi@gmail.com
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


//////////////////////////////////////< defination >//////////////////////////////////////////////////////////////
#ifndef CLREngi_main_class_h
#define CLREngi_main_class_h
//////////////////////////////////////< include >/////////////////////////////////////////////////////////////////
#include <d3dx9.h>
#include "include\\Utils\\CLREngi_ini_read.h"   
#include "include\\Utils\\Console.h"
#include "..\\import\\CRLEngi_strings_lib\\CRLEngi_strings.h"
#include "..\\import\\param_trees_lib\\param_trees.h" 
#include "Objects\\object_super_class.h" 
#include "include\\Managers\\Camera_Manager.h"
#include "include\\Managers\\Object_Manager.h"
#include "include\\Managers\\Event_Manager.h"
#include "include\\Managers\\Render_Manager.h"
#include "include\\Managers\\Light_Manager.h"
#include "include\\Managers\\Effect_Manager.h"
#include "include\\Utils\\defines01.h"  

#include "include\\lua\\lua_main.h"

#include "include\\Managers\\PhysX_Main.h"

#include "build.h"

//////////////////////////////////////< warning disables >/////////////////////////////////////////////////////////
#pragma warning (disable:4996)
//#################################################################################################################
////  СЕРДЦЕ ДВИЖКА CLREngi                                                                                   ////0
////  Автор: Пашинин Антон Алексеевич (crol)                                                                //////0
////  2008-2009 год                                                                                       ////////0
//#################################################################################################################
class CLREngi  ///
{              ///
///////////////////////////////////////< закрытые глобальные переменные>///////////////////////////////////////////
///////////////////////////////////////< открытые глобальные переменные>///////////////////////////////////////////
public:
	HWND                   *g_hWnd;
    LPDIRECT3D9             g_pD3D;               // Used to create the D3DDevice
    LPDIRECT3DDEVICE9       g_pd3dDevice;         // Our rendering device
	LPDIRECT3DDEVICE9      *d3dDevice;            // указатель на девайс, для объектов
	D3DLIGHT9               light;                // простой источник света

	D3DXMATRIXA16		    matWorld;             // мировая матрица 
	D3DXMATRIXA16           matView;
	D3DXMATRIXA16           matProj;
	/////////////// менеджеры
	CLREngi_Camera_Manager *Camera_Manager;
	CLREngi_Object_Manager *Object_Manager;
	CLREngi_Console        *Console;
	CLREngi_Event_Manager  *EventManager;
	CLREngi_Render_Manager *Render_Manager;
	CLREngi_Light_Manager  *Light_Manager;
	CLREngi_Effect_Manager *Effect_Manager;

	CLREngi_PhysX          *PhysX_Manager;

	CLua_Main               *Lua_Main;
	lua_State                    *lua;

	/////////////// цвета
	D3DCOLOR       BACK_RENDERER_COLOR;
	/////////////// шрифты
	LPD3DXFONT              Font8Verdana;         
	LPD3DXFONT              Font16Verdana;        
	LPD3DXFONT              Font6Kartika;   

	/////////////// параметры рендера
	unsigned short MULTISAMPLE_TYPE; 
	unsigned short FILLMODE;
	bool           MULTISAMPLEANTIALIAS;

	/////////////// текстуры разных цветов, нужны для раскраски спец объектов
	LPDIRECT3DTEXTURE9     *RedTexture; 
	LPDIRECT3DTEXTURE9     *WhiteTexture; 
	LPDIRECT3DTEXTURE9     *BlueTexture; 

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//#################################################################################################################
///////////////////////////////////////< функции >/////////////////////////////////////////////////////////////////	
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////                                                load_ini() функция загрузки параметров из файла инициализации
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	DynamicRow     load_ini   (char* namei){ // параметр - имя файла
   
		DynamicRow PARAMETERS; // Временная пременная для списка
		CRLEngi_string name;              // Временная переменная для передачи в загрузчик
	    name=namei;	                      // инициализируем ее
		CRLEngi_cIniReader INI1;		  // Экземпляр загрузчика файлов
		PARAMETERS=INI1.ReadIni(name);    // Загрузка параметров их файла
		INI1.~CRLEngi_cIniReader();       // Уничтожение загрузчика
		
		CRLEngi_string p1; 
        p1="treeEditor2.0\\loaded_parameters";
		PARAMETERS.iSaveToFile(p1);
        
		
		name = "file01";
		DynamicRow PARAMS;
		PARAMS.fresh();
		PARAMS.iLoadFromFile(name);

		return PARAMETERS;  
	}//DynamicRow


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void           Init_Parameters(DynamicRow *row){	   
		
		//общий сброс
		To_Default_All_Parameters();
		////////////////////////////////////////////////////////////////////////////////////////
        /////////////////////////////////////////////////                 параметры из структуры
		 if(row!=NULL){

			int	id    = (*row).iLookId("BACK_RENDERER_COLOR");
			unsigned int r,g,b;
			int count = (*row).iCountParams(id);
			if (id>0)
			  if (count==3){
				id = (*row).TopId(id);
				   r = ((*row).iLookName(id)).toInt();
				id = (*row).NextId(id);
				   g = ((*row).iLookName(id)).toInt();
				id = (*row).NextId(id);
				   b = ((*row).iLookName(id)).toInt();
				BACK_RENDERER_COLOR = D3DCOLOR_RGBA(r,g,b,1);
							
			    }//if

			id    = (*row).iLookId("MULTISAMPLE_TYPE");
			count = (*row).iCountParams(id);
			if (id>0)
				if (count==1){
					id = (*row).TopId(id);
				    r = ((*row).iLookName(id)).toInt();	
					MULTISAMPLE_TYPE   =	r;		
				}//if


			id    = (*row).iLookId("MULTISAMPLEANTIALIAS");
			count = (*row).iCountParams(id);
			if (id>0)
				if (count==1){
					id = (*row).TopId(id);
				    r = ((*row).iLookName(id)).toInt();	
					if ((r==1)||(r==0))
					MULTISAMPLEANTIALIAS   =	(bool)r;		
				}//if

			id    = (*row).iLookId("FILLMODE");
			count = (*row).iCountParams(id);
			if (id>0)
				if (count==1){
					id = (*row).TopId(id);
				    r = ((*row).iLookName(id)).toInt();	
					if ((r==1)||(r==2)||(r==3))
					FILLMODE   =	r;		
				}//if

		    }//if 
		 ////////////////////////////////////////////////////////////////////////////////////////
	
	
	
	}
	void           Init_Fonts(){

		////////////////////////////////////////////////////////////////////////////////////////
		/////////////////////////////////////////////////                                 шрифты 
			HRESULT hr;
			HDC hDC;
			int nHeight;
			int nPointSize = 8;

			hDC = GetDC( NULL );

			nHeight = -( MulDiv( nPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72 ) );

			ReleaseDC( NULL, hDC );

			hr = D3DXCreateFont( g_pd3dDevice, nHeight, 0, FW_BOLD, 0, FALSE, 
		                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 
		                 DEFAULT_PITCH | FF_DONTCARE, TEXT("Verdana"), 
		                 &Font8Verdana );

			nPointSize = 16;
			nHeight = -( MulDiv( nPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72 ) );
			hr = D3DXCreateFont( g_pd3dDevice, nHeight, 0, FW_BOLD, 0, FALSE, 
		                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 
		                 DEFAULT_PITCH | FF_DONTCARE, TEXT("Verdana"), 
		                 &Font16Verdana );		

			hr = D3DXCreateFont( g_pd3dDevice, 14,0, FW_NORMAL, 0, FALSE, 
		                 DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, 
		                 DEFAULT_PITCH | FF_DONTCARE, TEXT("Kartika"), 
		                 &Font6Kartika );	
	
	
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void           Init_Engine(){

		//инициализируем консоль
		 Console        = new CLREngi_Console(&g_pd3dDevice);	
		 CRLEngi_string  Buffer;

		d3dDevice        =  &g_pd3dDevice;
		D3DXMatrixIdentity( &matWorld);
		Init_Fonts();
        ////////////////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////                инициализация менеджеров 
		PhysX_Manager = new CLREngi_PhysX(Console);
		 
		 Camera_Manager = new CLREngi_Camera_Manager(&matWorld,Console);
		 Effect_Manager = new CLREngi_Effect_Manager(g_pd3dDevice,Camera_Manager,Console);		 
		 Light_Manager  = new CLREngi_Light_Manager(&matWorld,Console);
		 Object_Manager = new CLREngi_Object_Manager(&matWorld,d3dDevice,Effect_Manager,Light_Manager,PhysX_Manager,Camera_Manager,Console);
		 EventManager   = new CLREngi_Event_Manager(Camera_Manager,Object_Manager);

		 
		 

		// Lua_Main       = new CLua_Main(*Console);
		
		 Render_Manager = new CLREngi_Render_Manager(g_pd3dDevice,
													 Camera_Manager,
													 Object_Manager,
													 Light_Manager,
													 Console);	
		 

		 //EventManager = CEManager;
         CRLEngi_string text;
         text = "[>>>] build number : ";
         text.add(build_count);
         Console->AddText(text,3); //build_count

		 //EventManager = CEManager;
         text.clear();
         text = "[>>>] Build date : ";
         text.add(build_Day);text.add(".");
		 text.add(build_Month);text.add(".");
		 text.add(build_Year);text.add(" ");
		 text.add( " | time : ");
		 text.add(build_Hour+8);text.add(":");
		 text.add(build_Min);text.add(":");
		 text.add(build_Sec);text.add(" ");
         Console->AddText(text,3); //build_count
		 CRLEngi_string  Command;
		 


		 Console->AddText("[>>>] Initializing rendering manager : ",2); 
		 Render_Manager->Init();
		 Render_Manager->BACK_RENDERER_COLOR = BACK_RENDERER_COLOR;

		 Console->AddText("[>>>] Initializing PhysX manager : ",2); 
		 PhysX_Manager->InitPhysX();
		 
		 Console->SetTimeLine(&(EventManager->TimeLine));

		 //Console->SetEManger(EventManager);
		
		 Console->AddText("[>>>] Loading level : POLYGON01",2);

		 Console->AddText("[>>>] Loading Lights : ",2); 
		 Light_Manager->LoadFromRow("POLYGON01");
		 //Console->AddText("[i] Light Manager setup completed. ",3); 

		 Console->AddText("[>>>] Loading Objects : ",2); 
		 Object_Manager->LoadFromRow("POLYGON01");			

		Console->AddText("[>>>] Loading cameras : ",2);  		
		Camera_Manager->LoadFromRow("POLYGON01");
		Console->AddText("[i] Camera Manager setup completed. ",3); 

		Console->AddText("[>>>] Loading effects : ",2);  		
		Effect_Manager->LoadFromRow("POLYGON01");
		//Console->AddText("[i] Effect Manager setup completed. ",3); 

		//Console->AddText("[>>>] Lua setup : ",2);  		
		//Lua_Main->LuaInit();
		//Console->AddText("[i] Lua setup completed. ",3); 

		
        Object_Manager->Init_CharacterController();
		Object_Manager->Init_GlobalInterface();


        //SetupFromRow
		////////////////////////////////////////////////////////////////////////////////////////
		///////////////////////////////////////////////////////////             цветные текстуры
		WhiteTexture = new LPDIRECT3DTEXTURE9();	
		RedTexture   = new LPDIRECT3DTEXTURE9();	
		BlueTexture  = new LPDIRECT3DTEXTURE9();	
		if (FAILED(D3DXCreateTextureFromFile( g_pd3dDevice,  "textures\\_def\\white.bmp",  WhiteTexture)))
			Console->AddText("missed: textures\\_def\\white.bmp",1); 
		if (FAILED(D3DXCreateTextureFromFile( g_pd3dDevice,  "textures\\_def\\red.bmp",    RedTexture  )))
			Console->AddText("missed: textures\\_def\\red.bmp",1); 
		if (FAILED(D3DXCreateTextureFromFile( g_pd3dDevice,  "textures\\_def\\Blue.bmp",   BlueTexture )))
			Console->AddText("missed: textures\\_def\\Blue.bmp",1); 
             
		////////////////////////////////////////////////////////////////////////////////////////
		
	}//void
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	HRESULT        Init_DXGraphics_Default(HWND hWnd){
	
		g_hWnd = &hWnd;         //перехватываем адрес окна

		if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) ){
			//GRAPHICLOG.WriteLog_t("Direct3DCreate9 FAILED."); 
			return E_FAIL;
		    }

		 // Set up the structure used to create the D3DDevice. Since we are now
		 // using more complex geometry, we will create a device with a zbuffer.
		 D3DPRESENT_PARAMETERS d3dpp; 
		 ZeroMemory( &d3dpp, sizeof(d3dpp) );
		 d3dpp.Windowed               = true;
		 d3dpp.SwapEffect             = D3DSWAPEFFECT_DISCARD;//D3DSWAPEFFECT_COPY_VSYNC
		 d3dpp.BackBufferFormat       = D3DFMT_UNKNOWN;
		 d3dpp.EnableAutoDepthStencil = true;
		 d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
		 d3dpp.MultiSampleType        = (D3DMULTISAMPLE_TYPE)MULTISAMPLE_TYPE;

		 d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;//D3DPRESENT_INTERVAL_ONE

		 // Create the D3DDevice
		 if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      &d3dpp, &g_pd3dDevice ) ) ) {
			//GRAPHICLOG.WriteLog_t("CreateDevice FAILED.");
			return E_FAIL;
		    }
		 ////////////////////////////////////////(Настройки вывода DX)//////////////////////////////////////////////////
		 g_pd3dDevice->SetRenderState( D3DRS_ZENABLE,               TRUE );                   // Turn on the zbuffer
		 g_pd3dDevice->SetRenderState( D3DRS_ANTIALIASEDLINEENABLE, TRUE  );                  // слабое сглаживание 
			
		 g_pd3dDevice->SetRenderState( D3DRS_FILLMODE ,             FILLMODE );               // метод заполнения

		 g_pd3dDevice->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS,  MULTISAMPLEANTIALIAS );  

		 g_pd3dDevice->SetRenderState( D3DRS_AMBIENT,               0xffffffff );             // Turn on ambient lighting ffffffff 0x12345678
	     
         g_pd3dDevice->SetRenderState( D3DRS_CULLMODE,              D3DCULL_CCW );
 
		 g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, 3);
		 g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, 3);
		g_pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, 3);

		 g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, 3);

		g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSV , 1);
	    g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSU,  1);
		g_pd3dDevice->SetSamplerState(0, D3DSAMP_ADDRESSW,  1);

		//	 g_pd3dDevice->SetSamplerState(0, D3DSAMP_BORDERCOLOR, 1);

		 g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );

		 // This is how you find out how many texture stages your hardware will support
	     D3DCAPS9 caps;
	     g_pd3dDevice->GetDeviceCaps( &caps );
	     DWORD dwMaxTextureBlendStages = caps.MaxTextureBlendStages;
		 //g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

		 return S_OK;

		 
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void           SetupMatrices()
{
    // Set up world matrix
    D3DXMATRIXA16 matWorld;
    D3DXMatrixRotationY( &matWorld, timeGetTime()/1000.0f );
    g_pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

    // Set up our view matrix. A view matrix can be defined given an eye point,
    // a point to lookat, and a direction for which way is up. Here, we set the
    // eye five units back along the z-axis and up three units, look at the 
    // origin, and define "up" to be in the y-direction.
    D3DXVECTOR3 vEyePt( 0.0f, 3.0f,-5.0f );
    D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
    D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
   
    D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
    //g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );

    // For the projection matrix, we set up a perspective transform (which
    // transforms geometry from 3D view space to 2D viewport space, with
    // a perspective divide making objects smaller in the distance). To build
    // a perpsective transform, we need the field of view (1/4 pi is common),
    // the aspect ratio, and the near and far clipping planes (which define at
    // what distances geometry should be no longer be rendered).
    
    D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100000.0f );
    g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &matProj );
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	void           To_Default_All_Parameters(){
	 
	 MULTISAMPLE_TYPE     = 0;
	//// FILLMODE             = 3;
	 RedTexture           = NULL; 
     WhiteTexture         = NULL; 
     BlueTexture          = NULL;
	 Font6Kartika         = NULL;
	 Font8Verdana         = NULL;  
	 Font16Verdana        = NULL;  
	 BACK_RENDERER_COLOR  = D3DCOLOR_XRGB(100,130,170);
	 MULTISAMPLEANTIALIAS = false;
	
	}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void    Render(float FPSMSeconds,float elapsed){
	Render_Manager->Render_Default(FPSMSeconds,elapsed); 
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void           MakeActions(){
		if (!Console->visible){
		//EventManager->AnalyzeCommands();
		Object_Manager->run_commands();
		}
	}

//////////////////// when some button is pressed
void InputEvent(bool state){

		if((*Console).visible)
	     {
			     HGLOBAL hglb; 
                 LPSTR lpstr; 
                 if (OpenClipboard(*g_hWnd)) 
                  { 
                     hglb = GetClipboardData(CF_TEXT); 
                     lpstr = (LPSTR)GlobalLock(hglb);  
                     GlobalUnlock(hglb); 
                     CloseClipboard(); 
                   } 
				 if(!lpstr) lpstr ="";
			     (*Console).getKeyCommands(lpstr,state);
		 }
	
	
	}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CLREngi_Console*	GetConsole(){return Console;}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setScriptSource(lua_State *lu){
lua = lu;
Console->setScriptSource(lua);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///// 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void KeyboardInput( HWND hwnd ,float  Time){
	Camera_Manager->KeyInput(hwnd,Time);
	if (Camera_Manager->CurrientCamera->Camera->CameraName == "CC")
	       Object_Manager->KeyBoardInput(Time);

}

void MouseInput(HWND g_hWnd ,bool GMousing){
   Camera_Manager->MouseInput(g_hWnd,GMousing);
}
void MouseLButtonClick(){}
void MouseLButtonRelease(){}

void MouseRButtonClick(){}
void MouseRButtonRelease(HWND       *hwnd){

	D3DXVECTOR3 vPickRayDir;
    D3DXVECTOR3 vPickRayOrig;

	D3DXMATRIX matView;
	    D3DXMATRIX matProj,matW;
		D3DXVECTOR3 nWorld;	
		matView = Camera_Manager->CurrientCamera->Camera->CamView;
		matProj = Camera_Manager->CurrientCamera->Camera->CamProjection;
		nWorld = Camera_Manager->CurrientCamera->Camera->Look - Camera_Manager->CurrientCamera->Camera->Position;
		D3DXVec3Normalize(&nWorld,&nWorld);

		//g_pd3dDevice->GetTransform(D3DTS_VIEW,&matView);
		//g_pd3dDevice->GetTransform(D3DTS_PROJECTION,&matProj);
		
		g_pd3dDevice->GetTransform(D3DTS_WORLD,&matW);

	GetCurRay(hwnd, matWorld,matView,matProj,1024,768,&vPickRayDir,&vPickRayOrig);		

		//BOOL cool = false;
		//D3DXIntersect(g_pMesh,&vPickRayOrig,&vPickRayDir,&cool,NULL,NULL,NULL,NULL,NULL,NULL);
		//GMousing = false;

	Object_Manager->SendMouseClickEvent(&vPickRayDir,&vPickRayOrig);


}
//#################################################################################################################
///////////////////////////////////////< конструктор/деструктор >//////////////////////////////////////////////////
	public:
	CLREngi(){	};
	virtual ~CLREngi(){	

	Console->Save("LOG.dr");


	SAFE_RELEASE(RedTexture);
	SAFE_RELEASE(WhiteTexture);
	SAFE_RELEASE(BlueTexture);

	SAFE_RELEASE_P(Font8Verdana);
	SAFE_RELEASE_P(Font16Verdana);
	SAFE_RELEASE_P(Font6Kartika);

	SAFE_RELEASE_P(g_pD3D);
	SAFE_RELEASE_P(g_pd3dDevice);

	//SAFE_RELEASE_P(light);

	Camera_Manager->~CLREngi_Camera_Manager();
	Object_Manager->~CLREngi_Object_Manager();
	Console->~CLREngi_Console();
	EventManager->~CLREngi_Event_Manager();
	Render_Manager->~CLREngi_Render_Manager();
	Light_Manager->~CLREngi_Light_Manager();
	Effect_Manager->~CLREngi_Effect_Manager();
	
	};

};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////0

#endif
